<template>
  <view class="good_info_container">
    <!-- 商品展示区域 -->
    <view class="goods_container">
      <view
        class="goodsInfo_box"
        v-for="(item, index) in goodsList"
        :key="index"
      >
        <view class="goodsinfo">
          <image class="avatar" :src="item.goods.cover_image"></image>
          <view class="right">
            <view class="goods_title">{{ item.goods.goods_title }}</view>
            <view class="goods_btn">
              <van-button custom-class="btn public" @tap="goodsUp(item)">{{
                item.goods.goods_status == 0 ? "上架" : "下架"
              }}</van-button>
              <van-button custom-class="btn">编辑</van-button>
              <van-button custom-class="btn">删除</van-button>
            </view>
            <view class="goods_btn" v-if="type == 'near'">
              <!-- <van-button custom-class="btn public" @tap="goodsUp(item)" >{{item.goods.goods_status==0?'上线':'下线'}}</van-button> -->
              <van-button
                custom-class="btn"
                color="#7232dd"
                @tap="set_mchnear_goods(item)"
                 v-if="out"
                >设置商品</van-button
               
              >
              <van-button
                custom-class="btn"
                color="#3CC457"
                @tap="set_tj_goods(item)"
                 v-if="promotion"
                >推广</van-button
              >
            </view>
          </view>
        </view>
        <view class="goodsdata">
          <view class="data_title">
            <view class="price gray">价格(元)</view>
            <view class="commision gray">佣金率</view>
            <view class="status gray">状态</view>
            <view class="num_remain gray">库存</view>
          </view>
          <view class="data_count">
            <view class="price black"
              >{{ item.goods.price2 }}~{{ item.goods.price }}</view
            >
            <view class="commision black"
              >{{ item.goods.commission_rate * 100 }}%</view
            >
            <view class="status black">{{
              statusList[item.goods.goods_status]
            }}</view>
            <view class="num_remain black">{{
              item.goods.goods_total_amt
            }}</view>
          </view>
        </view>
      </view>
    </view>
    <!-- 商品展示区域 -->
   
  </view>
</template>

<script>
import { update_status } from "../../utils/imapi";
const statusList = {
  0: "仓库中",
  1: "上架审核",
  2: "提审中",
  3: "审核成功",
  4: "审核失败",
};
export default {
  name: "GoodInfo",
  props: {
    goodsList: {
      type: Array,
      required: true,
    },
    type: {
      type: String,
    },
    out:{
      type:Boolean,
      default:true
    },
    promotion:{
       type:Boolean,
      default:true
    },
  },
  components: {},
  data() {
    return {
      statusList,
    };
  },
  computed: {},
  watch: {},
  onLoad() {
    console.log(this.goodsList);
    console.log(this.type);
  },
  onReady() {},
  onShow() {},
  methods: {
    async goodsUp(item) {
      const id = item.goods.id;
      console.log(id);
      if (item.goods.goods_status == 0) {
        try {
          const data = await update_status({
            g_id: id,
            status: "1",
          });
          if (data.code == 0) {
            this.$toast.success("上架申请已提交， 等待审核...");
            this.$emit("reload");
          }
        } catch (error) {
          this.$toast.fail("上架申请失败,请稍后重试");
        }
      } else {
        try {
          const data = await update_status({
            g_id: id,
            status: "0",
          });
          if (data.code == 0) {
            this.$toast.success("下架成功");

            this.$emit("reload");
          }
        } catch (error) {
          this.$toast.fail("下架失败,请稍后重试");
        }
      }
     
    },
     set_mchnear_goods(item) {
        this.$emit('set_goods',item)
      },
     set_tj_goods(item) {
        this.$emit('set_tg',item)
      },
  },
  onReachBottom() {},
  onHide() {},
};
</script>

<style scoped lang="scss" scoped>
.query_container {
  .goodsInfo_box {
    padding: 32upx;
    border-bottom: 16upx solid #f0eefd;
    .goodsinfo {
      display: flex;
      align-items: center;
      margin-bottom: 20upx;
      .avatar {
        width: 160upx;
        height: 160upx;
        margin-right: 20upx;
      }
      .right {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .goods_title {
          width: 494upx;
          max-height: 80upx;
          text-align: left;
          font-size: 26upx;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #0a0819;
          text-overflow: ellipsis;
          overflow: hidden;
        }
        .goods_btn {
          display: flex;
          align-items: center;
          justify-content: flex-end;
          margin-bottom: 10upx;
          /deep/ .btn {
            min-width: 160upx;
            height: 64upx;
            background: #fff;
            border-radius: 10upx;
            font-size: 26upx;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #0a0819;
            line-height: 64upx;
            text-align: center;
            margin-left: 10upx;
          }
          /deep/ .public {
            background: #6d55ed !important;
            color: #ffffff !important;
          }
        }
      }
    }
    .goodsdata {
      .data_title,
      .data_count {
        display: flex;
        .price {
          width: 224upx;
          padding-left: 20upx;
        }
        .commision {
          width: 136upx;
          padding-left: 14upx;
        }
        .status {
          width: 132upx;
          padding-left: 14upx;
        }
        .num_remain {
          width: 200upx;
          text-align: right;
          padding-right: 20upx;
        }
        .black {
          border: 1px solid #f0eefd;
        }
      }
      .data_title {
        height: 38upx;
        font-size: 10upx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #727278;
        line-height: 38upx;
      }
      .data_count {
        height: 58upx;
        font-size: 26upx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #0a0819;
        line-height: 58upx;
      }
    }
  }
}
</style>
